package com.skit.main.ui.type

import android.util.Log
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.skit.common.base.mvvm.BaseActivity
import com.skit.common.bean.ActivityBean
import com.skit.common.config.RouteConfig
import com.skit.common.http.HttpUtils
import com.skit.main.R
import com.skit.main.databinding.MainActivityTypeListBinding
import com.skit.common.retrofit.ActivityProtocol
import com.skit.main.ui.type.adapter.ActivityTypeDataAdapter
import dagger.hilt.android.AndroidEntryPoint
import retrofit2.Retrofit
import javax.inject.Inject

@AndroidEntryPoint
@Route(path = RouteConfig.MainRoute.MAIN_ACTIVITY_TYPES)
class ActivityTypeActivity : BaseActivity<MainActivityTypeListBinding>() {
    companion object {
        private const val TAG = "ActivityType"
    }

    @Inject
    lateinit var retrofit: Retrofit

    override val layoutResId: Int
        get() = R.layout.main_activity_type_list

    private val list: ArrayList<ActivityBean.TypeBean> = ArrayList()

    val typeAdapter: ActivityTypeDataAdapter by lazy { ActivityTypeDataAdapter(list) }

    override fun initData() {
        val create = retrofit.create(ActivityProtocol::class.java)
        val activityType = create.activityType
        HttpUtils.doRequest(activityType) {
            if (it != null && it.isSuccess) {
                list.addAll(it.data)
                typeAdapter.notifyDataSetChanged()
            } else {
                Log.d(TAG, "error: ${it?.msg}")
            }
        }
    }

    override fun initConfig() {

    }

    override fun initView() {
        binding.recyclerView.apply {
            adapter = typeAdapter
            layoutManager = LinearLayoutManager(this@ActivityTypeActivity)
        }
    }

}